<?php
function renderForm($result)
{
?>
<!---------------------------------HTML CODES------------------------------------------------------>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta name="Description" content="Clinic Management System" />
	<link rel="stylesheet" href="../includes/Style.css" type="text/css" />
	<title>OPTICSoft</title>
</head>
<body>  
<?php include('../includes/header.php');?>
<div id="content-wrap"><div id="content">
  
  <?php displayMessage(); ?>
  <?php include('sidebar.php');?>
   
  <div id="main"><div class="post">  	
	<h1>Supplier List </h1>	
	<h3><?php if($result!=null) echo mysql_num_rows($result);else  '0'; ?> Records</h3>
	<table>
		<tr>
			<th class="first"><strong>Code</strong></th>
			<th> Name </th>
			<th> Action </th>
		</tr>
		<?php
		$rowCount = 0;
		if($result!=null)
		{
		  while ($row = mysql_fetch_assoc($result)) {
		     if ($rowCount % 2 == 0)
			 echo '<tr class="row-a">';
		     else
		         echo '<tr class="row-b">';
		     $rowCount++;
		     echo '<td align="left">'.$row["Code"].'</td>';
		     echo '<td align="left">'.$row["Supplier"].'</td>';		     
		     echo  '<td> <a href="Supplier.php?Code='.$row["Code"].'">[Update] </a>'.
	                  '<a href="SupplierList.php?Code='.$row["Code"].'"> [Delete]</a> </td>';
		     echo '</tr>';
		  }
		}
		?>	
      </table>		
</div></div></div></div>
</body>
</html>
<!-------------------------------------------------------------------------------------------------------->
<?php
}
  //include statement
  require("supplier.inc");
  $supplier = new Supplier();
  global $result;
  
  if (isset($_GET['Code'])) //RECORD SELECTED FOR DELETE
  { 
   	$supplier->delete($_GET['Code']);
        setcookie("message", "Record Removed.", time() + 3);
	header('location:SupplierList.php');
	exit();
  }
  if (isset($_POST['search_query']) && $_POST['search_query'] != '') //FIND SUPPLIER
       $result = $supplier->retrieveByName($_POST['search_query']);
  else
       $result = $supplier->retrieve();
  	
  renderForm($result);
  //FUNCTIONS
  function displayMessage()
  {
     if(isset($_COOKIE['message']))
        echo '<div id="notification">'.$_COOKIE["message"].'</div>';
  }
?>
